package de.uni_mannheim.informatik.ai.dame_ai.util;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

@SuppressWarnings("serial")
public class CommonMenuBar extends JMenuBar{

	protected JMenu start=new JMenu("Start");
	protected JMenu replay=new JMenu("Replay");
	protected JMenu help=new JMenu("Help");
	protected JMenuItem newGame=new JMenuItem("New Game");
	protected JMenuItem restart=new JMenuItem("Restart Game");
	protected JMenuItem quickSave=new JMenuItem("Quick Save");
	protected JMenuItem quickLoad=new JMenuItem("Quick Load");
	protected JMenuItem saveGame=new JMenuItem("Save...");
	protected JMenuItem loadGame=new JMenuItem("Load...");
	protected JMenuItem exit=new JMenuItem("Exit");
	protected JMenuItem repCurrent=new JMenuItem("Replay Current Game");
	protected JMenuItem repSaved=new JMenuItem("Replay Saved Game...");
	protected JMenuItem rules=new JMenuItem("Rules");
	protected JMenuItem info=new JMenuItem("Info");
	
	public CommonMenuBar() {
		start.add(newGame);
		start.add(restart);
		start.addSeparator();
		start.add(quickSave);
		start.add(quickLoad);
		start.add(saveGame);
		start.add(loadGame);
		start.addSeparator();
		start.add(exit);
		replay.add(repCurrent);
		replay.add(repSaved);
		help.add(rules);
		help.add(info);
		this.add(start);
		this.add(replay);
		this.add(help);
	}
	
	
	public void addCommonMenuBarListener(final CommonMenuBarListener cmbl){
		//add action listeners
		newGame.addActionListener(new ActionListener() {
			@Override	
			public void actionPerformed(ActionEvent e) {
				cmbl.newGame();
			}
		});
		restart.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.restart();
			}
		});
		quickSave.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.quickSave();
			}
		});
		
		quickLoad.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.quickLoad();
			}
		});
		saveGame.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.saveGame();
			}
		});
		loadGame.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.loadGame();
			}
		});
		exit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.exit();
			}
		});
		repCurrent.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.replayCurrent();
			}
		});
		repSaved.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.replaySaved();
			}
		});
		rules.addActionListener(new ActionListener() {
			@Override	public void actionPerformed(ActionEvent e) {
				cmbl.showRules();
			}
		});
		info.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cmbl.showInfo();
			}
		});
	}
}
